//
//  RegistViewController.m
//  UI3_作业1
//
//  Created by Maxdong on 14-12-1.
//  Copyright (c) 2014年 lanou3g.com 蓝欧科技. All rights reserved.
//

#import "RegistViewController.h"
#import "ShowViewController.h"
#import "SCViewController.h"


@interface RegistViewController ()

@end

@implementation RegistViewController


- (void)dealloc
{
    [super dealloc];
}

- (instancetype)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self =[super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        
    }
    return self;
}

//- (void)createView{
//    RegistView * rv =[[RegistView alloc] initWithFrame:CGRectMake(0 ,80,270,30) text:nil ];
//    [self.view addSubview:rv];
//    
//}

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor =[UIColor colorWithPatternImage:[UIImage imageNamed:@"our.png"]];
   // [self RegistView];
    //[self createView];
    [self createButton];
    
}



- (void)createButton
{

    self.aLabel = [[UILabel alloc]initWithFrame:CGRectMake(40, 150, 80, 40)];
    [_aLabel setTextColor:[UIColor whiteColor]];
    [self.view addSubview:_aLabel];
    [_aLabel setText:@"用户名 :"];
    [_aLabel release];
    
    
    self.bLabel =[[UILabel alloc] initWithFrame:CGRectMake(40, 200, 80, 40)];
    [_bLabel setTextColor:[UIColor whiteColor]];
    [self.view addSubview:_bLabel];
    [_bLabel setText:@"密  码:"];
    [_bLabel release];
    
    self.cLabel =[[UILabel alloc] initWithFrame:CGRectMake(40, 250, 80, 40)];
    [_cLabel setTextColor:[UIColor whiteColor]];
    [self.view addSubview:_cLabel];
    [_cLabel setText:@"确认密码:"];
    [_cLabel release];
    
    
    self.dLabel =[[UILabel alloc] initWithFrame:CGRectMake(40, 300, 80, 40)];
    [_dLabel setTextColor:[UIColor whiteColor]];
    [self.view addSubview:_dLabel];
    [_dLabel setText:@"手机号码:"];
    
    [_dLabel release];
    
    self.yLabel =[[UILabel alloc] initWithFrame:CGRectMake(40, 350, 80, 40)];
    [_yLabel setTextColor:[UIColor whiteColor]];
    [self.view addSubview:_yLabel];
    [_yLabel setText:@"邮  箱"];
    [_yLabel release];
    
    
    
    self.utf = [[UITextField alloc] initWithFrame:CGRectMake(140, 150, 180, 30)];
    [_utf setBorderStyle:UITextBorderStyleRoundedRect]; //外框类型
    [self.view addSubview:_utf];
    _utf.placeholder = @"UserName"; //默认显示的字
    _utf.tag =10;
    _utf.delegate=self;
    [_utf release];
    
    
    self.utf2 =[[UITextField alloc] initWithFrame:CGRectMake(140, 200, 180, 30)];
    [self.view addSubview:_utf2];
    [_utf2 setBorderStyle:UITextBorderStyleRoundedRect];
    _utf2.tag=20;
    _utf2.placeholder =@"PassWord";
    [_utf2 setSecureTextEntry:YES];
    [_utf2 release];
    
    
    self.utf3 =[[UITextField alloc] initWithFrame:CGRectMake(140, 250, 180, 30)];
    [self.view addSubview:_utf3];
    [_utf3 setBorderStyle:UITextBorderStyleRoundedRect];
    _utf3.placeholder =@"AgainPassWord";
    [_utf3 setSecureTextEntry:YES];
    _utf3.tag=30;
    [_utf3 release];
    
    self. utf4 =[[UITextField alloc] initWithFrame:CGRectMake(140, 300, 180, 30)];
    [self.view addSubview:_utf4];
    [_utf4 setBorderStyle:UITextBorderStyleRoundedRect];
    _utf4.placeholder =@"PhoneNumber";
    [_utf4 setKeyboardType:UIKeyboardTypeNumberPad];
    _utf4.tag=40;
    [_utf4 release];
    
    self.utf5 =[[UITextField alloc] initWithFrame:CGRectMake(140, 350, 180, 30)];
    [self.view addSubview:_utf5];
    [_utf5 setBorderStyle:UITextBorderStyleRoundedRect];
    _utf5.placeholder =@"Email";
    _utf5.tag=50;
    [_utf5 release];
    
    
    //you
    UIButton *button =[[UIButton alloc] initWithFrame:CGRectMake(260, 30, 50, 40)];
    [button setTitle:@"注册" forState:UIControlStateNormal];
    [button setTitleColor:[UIColor yellowColor] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(buttonsAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button];
    
    //zuo
    UIButton *button22 =[[UIButton alloc] initWithFrame:CGRectMake(30, 30, 25, 25)];
    UIImage * img =[UIImage imageNamed:@"backkk.png"];
    [button22 setBackgroundImage:img forState:UIControlStateNormal];
    [button22 addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:button22];

    
}

//注册
- (void)buttonsAction:(id)sender
{
        UITextField * text1 =(UITextField *)[self.view viewWithTag:10];
        UITextField * text2 =(UITextField *)[self.view viewWithTag:20];
        UITextField * text3 =(UITextField *)[self.view viewWithTag:30];
        UITextField * text4 =(UITextField *)[self.view viewWithTag:40];
        UITextField * text5 =(UITextField *)[self.view viewWithTag:50];
        if ([text1.text isEqualToString:@"zhangsan"] && [text2.text isEqualToString:@"123"] && [text3.text isEqualToString:@"123"] && [text4.text isEqualToString:@"110"] && [text5.text isEqualToString:@""]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"注册成功" message:@"欢迎光临" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:nil, nil];
            [alert show];
    
            [self.navigationController popViewControllerAnimated:YES];
        }else if ([text1.text isEqualToString:@""] || [text2.text isEqualToString:@""] || [text1.text isEqualToString:nil] || [text2.text isEqualToString:nil]) {
            UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"注册信息不完整" message:@"请重新输入信息" delegate:self cancelButtonTitle:@"确定" otherButtonTitles:@"取消", nil];
            [alert show];
    }
}
- (void)buttonAction:(UIButton *)sender
{
    
    [self dismissViewControllerAnimated:YES completion:nil];
   

}

-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
    UITextField * text1 =(UITextField *)[self.view viewWithTag:10];
    UITextField * text2 =(UITextField *)[self.view viewWithTag:20];
    UITextField * text3 =(UITextField *)[self.view viewWithTag:30];
    UITextField * text4 =(UITextField *)[self.view viewWithTag:40];
    UITextField * text5 =(UITextField *)[self.view viewWithTag:50];

    [text1 resignFirstResponder];
    [text2 resignFirstResponder];
    [text3 resignFirstResponder];
    [text4 resignFirstResponder];
    [text5 resignFirstResponder];
    
}





- (BOOL)textFieldShouldReturn:(UITextField *)textField
{
    //取消第一响应者  让键盘消失
    [textField resignFirstResponder];
    return YES;
}




- (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
